<?php

/**  日志类
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/19
 * Time: 20:04
 */
class class_logger
{
    private $log_path = "c:/logger"; //日志保存的路径
    private $log_filename_format = "%Y-%m-%d"; //日志文件名格式
    function __construct()
  {
      if(! file_exists_case($this->log_path)){
          mkdir($this->log_path);
      }
  }

    /**  设置日志保存位置路径
     * @param $logPath 路径格式：C:/myinfo/log
     */
   function  Set_Path($logPath){
        $logPath = str_replace('\\','/',$logPath);
        if(! preg_match('#\b[a-zA-Z]:[\\/](?:[^\\/:*?"<>|\r\n]+)*#i',$logPath)){
            return ;
        }
        $array_dir = preg_split("/[\/]/",$logPath);
        $full_path ="";
        foreach ($array_dir as  $d){
            $full_path = $full_path.$d;
            if(! file_exists_case($full_path)){mkdir($full_path);}
        }
        $this->log_path = $logPath;
   }



    const logtype_INFO = 0; // 信息
    const logtype_DEBUG = 2; //调试信息
    const logtype_NOTICE = 4; //通知 程序可以运行
    const logtype_WARN = 8; //警告 可能造成错误
    const logtype_ERROR = 16;//错误 代码执行遇到错误
    const logtype_FATAL = 32;//致命失败

}